package com.unknown.wiki;

import android.os.Bundle;
import android.widget.TextView;

import com.unknown.common.function.EEFunction;
import com.unknown.common.function.SEFunction;
import com.unknown.common.util.ActivityUtils;
import com.unknown.common.util.StringUtils;
import com.unknown.wiki.base.BaseActivity;

public class SplashActivity extends BaseActivity {
    private TextView tvTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        init();
    }

    @Override
    protected void onResume() {
        super.onResume();

        SEFunction<Long> onTick = this::onTick;
        EEFunction onFinish = this::onFinish;

        long loadTime = 4000; //milliseconds
        long countDownInterval = 1000; //milliseconds

        getServiceManager()
                .getCountDownTimerService(loadTime, countDownInterval, onTick, onFinish)
                .startService();
    }

    private void init() {
        tvTimer = findViewById(R.id.splash_timer_tv);
    }

    private void onTick(long millisInFuture) {
        tvTimer.setText(StringUtils.concat(getString(R.string.splash_timer), millisInFuture / 1000));
    }

    private void onFinish() {
        ActivityUtils.startActivity(this, WikiListActivity.class, true);
    }
}
